import http from '../../utils/http.js'


export function getChargingDetail(id){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/charging/detail',
		   method:'GET',
		   data:{
			   chargingId: id
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function startCharge(chargingSocketId,BillingGroupPlanId){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/charging/start/charge',
		   method:'POST',
		   data:{
			   chargingSocketId: chargingSocketId,
			   billingGroupPlanId: BillingGroupPlanId
		   },
		   callBack:(res)=>{
			if(res.code==0 ||  res.code == 1041){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function confirmCharge(orderNumber){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/charging/confirm/charge/result',
		   method:'GET',
		   data:{
			   orderNumber: orderNumber
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}else if(res.code==1048){
			 resolve(res)	
			}else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function endCharge(orderNumber){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/charging/finish/charge',
		   method:'POST',
		   data:{
			   orderNumber: orderNumber
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function getCarChargingSocketDetail(id){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/car/charging/socket/detail',
		   method:'GET',
		   data:{
			   chargingSocketId: id
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}


export function startCarCharge(billingPlanId,billingType,billingValue,socketId){
	console.log(billingValue)
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/car/charging/start/charge',
		   method:'POST',
		   data: {
			   carGroupBillingPlanId: billingPlanId,
			   billingType: billingType,
			   billingValue: billingValue,
			   carChargingSocketId: socketId
		   },
		   callBack:(res)=>{
			if(res.code==0 || res.code == 1041){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function endCarCharge(orderNumber){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/car/charging/end/charge',
		   method:'POST',
		   data: {
			   orderNumber: orderNumber
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function confirmCarOrderResult(orderNumber){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/car/charging/confirm/charge/result',
		   method:'GET',
		   data: {
			   orderNumber: orderNumber
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}else if(res.code==1048){
			 resolve(res)	
			}else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function getCarChargingDetail(id){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/car/charging/detail',
		   method:'GET',
		   data:{
			   chargingId: id
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function getActivityInfo(groupId){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/new/user/activity/get',
		   method:'GET',
		   data:{
			   chargingGroupId: groupId
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}

export function receiveActivity(groupId){
	return new Promise((resolve,reject)=>{
		var params={
		   url:'/v1/app/new/user/activity/get/new/member/activity/info',
		   method:'GET',
		   data:{
			   chargingGroupId: groupId
		   },
		   callBack:(res)=>{
			if(res.code==0){
			 resolve(res)
			}
			else{
			 reject(res.msg)
			}
		}
	  }
	  http.request(params)
	})
}
